<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>现金卡入库</title>
    <style type="text/css">
        .items2 ul{ }
        .items2 ul li{margin-bottom: 10px;border: 1px solid #ffffff;height: 30px;line-height: 30px;padding: 0 5px;}
        .items2 ul li.selected {background-color: #E8F1FF;border: 1px solid #B2D1FF;box-shadow: 2px 2px 0 #E5E5E5;font-weight: bold;}
    </style>
</head>

<body>
<div style="width:98%; margin: 0 auto;">

    <div class="title">
        <h2 class="tac">
            现金卡入库
        </h2>
    </div>

    <!--现金卡信息-->

    <div class=" panel panel-default">
        <h2 class="panel-heading">
            现金卡信息
        </h2>
        <table class="table">
            <thead>
            <tr>

            </tr>
            </thead>
            <thead>
            <tr>
                <th>面值</th>
                <th>规格</th>
                <th>生产数量</th>
                <th>备注</th>
            </tr>
            </thead>

            <tbody>
            <!--{foreach from=$card_master_array item=card_detail}-->
            <tr>
                <td><!--{$card_detail.face_value}--></td>
                <td><!--{$card_detail.card_spec}--></td>
                <td><!--{$card_detail.card_product_number}--></td>
                <td><!--{$card_detail.remark}--></td>
            </tr>
            <!--{/foreach}-->
            </tbody>

        </table>
    </div>


    <div class=" panel panel-default">
        <h2 class="panel-heading">
            卡号信息
        </h2>
        <div class="panel-body">

            <table class="form-inline">
                <tbody>
                <tr>
                    <td width="300">起始卡号：<input type="text" class="form-control w150" id="card_no_start" placeholder="扫描起始卡号" /></td>
                    <td width="300">结束卡号：<input type="text" class="form-control w150" id="card_no_end" placeholder="扫描结束卡号" /></td>
                    <td width="*"><button type="button" class="btn btn-success" id="allocation">入库新增</button></td>
                </tr>
                </tbody>
            </table>
            <br>
            <br>
            <table class="table">
                <thead>
                <tr>
                    <th> 起始卡号 </th>
                    <th> 结束卡号 </th>
                    <th> 入库数量 </th>
                    <th> 面值 </th>
                    <th> 规格 </th>
                    <th> 操作 </th>
                </tr>
                </thead>
                <tbody id="card_list">

                </tbody>
                <tbody>
                <tr>
                    <td colspan="6">
                        <button type="button" class="btn btn-primary" onclick="cardList.save();">入库激活</button>&nbsp;&nbsp;
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!--{if $card_put_array}-->
        <div class="panel panel-default">

            <div class="panel-heading">入库列表</div>
            <table class="table">
                    <thead>

                        <tr>
                            <th width="300">起始卡号</th>
                            <th width="200">结束卡号</th>
                            <th width="200">入库数量</th>
                            <th width="100">面值</th>
                            <th width="50"> 规格 </th>
                        </tr>
                    </thead>

                <tbody class="form-inline" id="invoice_list">
                <!--{if $card_put_array}-->
                    <!--{foreach from=$card_put_array item=card_put_save}-->
                        <tr>
                            <td><!--{$card_put_save.card_no_start}--></td>
                            <td><!--{$card_put_save.card_no_end}--></td>
                            <td><!--{$card_put_save.card_warehouse_voucher_number}--></td>
                            <td><!--{$card_put_save.face_value}--></td>
                            <td><!--{$card_put_save.card_spec}--></td>
                        </tr>
                    <!--{/foreach}-->
                <!--{/if}-->
                </tbody>
            </table>
        </div>
    <!--{/if}-->

</div>


<script type="text/javascript">

$('#card_no_start').keypress(function(event) {

    if (event.keyCode == 13) {

        var card_no = E.trim($(this).val());

        if (E.isEmpty(card_no)) {
            E.alert('起始卡号不能为空', 1, function() {
                $('#card_no_start').focus();
            });
            return false;
        }

        if (!E.isDigital(card_no) || card_no.length != 13) {
            E.alert('卡号必须13位的整数', 1, function() {
                $('#card_no_start').focus();
            });
            return false;
        }

        $('#card_no_end').focus();

    }

});

$('#card_no_end').keypress(function(event) {

    if (event.keyCode == 13) {

        var card_no = E.trim($(this).val());
        var card_no_start = E.trim($('#card_no_start').val());

        if (E.isEmpty(card_no)) {
            E.alert('结束卡号不能为空', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        if (!E.isDigital(card_no) || card_no.length != 13) {
            E.alert('卡号必须13位的整数', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        if (card_no < card_no_start) {
            E.alert('结束卡号不能小于开始卡号', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        $('#allocation').trigger('click');

    }

});

$('#allocation').click(function() {
    cardList.allocation();
});

var cardList = {

    card_id:<!--{$card_id}-->,

    index: 1,

    card_detail: {},

    allocation: function() {

        var card_no_start = E.trim($('#card_no_start').val());
        var card_no_end = E.trim($('#card_no_end').val());

        if (E.isEmpty(card_no_start)) {
            E.alert('起始卡号不能为空', 1, function() {
                $('#card_no_start').focus();
            });
            return false;
        }

        if (!E.isDigital(card_no_start) || card_no_start.length != 13) {
            E.alert('卡号必须13位的整数', 1, function() {
                $('#card_no_start').focus();
            });
            return false;
        }

        if (E.isEmpty(card_no_end)) {
            E.alert('结束卡号不能为空', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        if (!E.isDigital(card_no_end) || card_no_end.length != 13) {
            E.alert('卡号必须13位的整数', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        if (card_no_end < card_no_start) {
            E.alert('结束卡号不能小于开始卡号', 1, function() {
                $('#card_no_end').focus();
            });
            return false;
        }

        E.loadding.open('正在检查现金卡，请稍候...');

        E.ajax_get({
            url: '/invokingAjax-backend/company/card.ajax?operFlg=5',
            data: {
                card_id: this.card_id,
                card_no_start: card_no_start,
                card_no_end: card_no_end
            },

            call: function( o ) {

                E.loadding.close();

                if (o.code == 200) {

                    var html = '<tr id="card_line_' + cardList.index + '">';
                    html += '<td>' + card_no_start + '</td>';
                    html += '<td>' + card_no_end + '</td>';
                    html += '<td>' + o.data.card_product_number + '</td>';
                    html += '<td>' + o.data.face_value + '</td>';
                    html += '<td>' + o.data.card_spec + '</td>';
                    html += '<td><a href="javascript: void(0);" onclick="cardList.del(' + cardList.index + ');">删除</a></td>';
                    html += '</tr>';
                    $('#card_list').append(html);
                    cardList.card_detail[cardList.index] = {
                        card_no_start: card_no_start,
                        card_no_end: card_no_end
                    };
                    cardList.index++;
                    $('#card_no_start').val('').focus();
                    $('#card_no_end').val('');

                } else {

                    E.alert(o.message);

                }

            }
        });

    },

    del: function(index) {
        $('#card_line_' + index).remove();
        delete cardList.card_detail[index];
    },

    save: function() {

        var count = 0;
        $.each(cardList.card_detail, function(k, v) {
            count++;
        });

        if (count == 0) {
            E.alert('请录入现金卡', 1, function() {
                $('#card_no_start').focus();
            });
        } else {

            E.confirm('您确认要激活录入的现金卡吗？', function() {
                E.ajax_post({
                    url: '/invokingAjax-backend/company/card.ajax?operFlg=6',
                    data: {
                        card_id: cardList.card_id,
                        card_detail: cardList.card_detail
                    },
                    call: function( o ) {

                        E.loadding.close();

                        if (o.code == 200) {

                            E.opener('cardList.load');
                            E.alert(o.message, 2, function() {
                                E.closeWindows();
                            });

                        } else {

                            E.alert(o.message);

                        }

                    }
                });
            });

        }

    }

};

</script>


</body>
</html>
